using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WowDotNetAPI.Models;

namespace WowDotNetAPI.Test
{
    [TestClass]
    public class CharacterTestSL : SilverlightTest
    {
        [TestMethod]
        [Asynchronous]
        public void Get_Simple_Character_Briandek_From_Skullcrusher()
        {
            bool done = false;
            var WowExplorer = new WowExplorer(Region.US);

            Character briandek = null;
            WowExplorer.GetCharacter("skullcrusher", "briandek", cb =>
                    {
                        briandek = cb.Result;
                        done = true;
                    });

            EnqueueConditional(() => done);
            EnqueueCallback(() => Assert.IsNull(briandek.Guild));
            EnqueueCallback(() => Assert.IsNull(briandek.Stats));
            EnqueueCallback(() => Assert.IsNull(briandek.Talents));
            EnqueueCallback(() => Assert.IsNull(briandek.Items));
            EnqueueCallback(() => Assert.IsNull(briandek.Reputation));
            EnqueueCallback(() => Assert.IsNull(briandek.Titles));
            EnqueueCallback(() => Assert.IsNull(briandek.Professions));
            EnqueueCallback(() => Assert.IsNull(briandek.Appearance));
            EnqueueCallback(() => Assert.IsNull(briandek.Companions));
            EnqueueCallback(() => Assert.IsNull(briandek.Mounts));
            // EnqueueCallback(() =>      Assert.IsNull(briandek.Pets));
            EnqueueCallback(() => Assert.IsNull(briandek.Achievements));
            EnqueueCallback(() => Assert.IsNull(briandek.Progression));

            EnqueueCallback(() => Assert.IsTrue(briandek.Name.Equals("briandek", StringComparison.InvariantCultureIgnoreCase)));
            EnqueueCallback(() => Assert.AreEqual(85, briandek.Level));
            EnqueueCallback(() => Assert.AreEqual(CharacterClass.WARRIOR, briandek.@Class));
            EnqueueCallback(() => Assert.AreEqual(CharacterRace.HUMAN, briandek.Race));
            EnqueueCallback(() => Assert.AreEqual(CharacterGender.MALE, briandek.Gender));
            EnqueueTestComplete();
        }

        [TestMethod]
        [Asynchronous]
        public void Get_Complex_Character_Briandek_From_Skullcrusher()
        {
            bool done = false;
            var WowExplorer = new WowExplorer(Region.US);

            Character briandek = null;
            WowExplorer.GetCharacter("skullcrusher", "briandek", CharacterOptions.GetEverything, cb =>
            {
                briandek = cb.Result;
                done = true;
            });


            EnqueueConditional(() => done);
            EnqueueCallback(() => Assert.IsNotNull(briandek.Guild));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Stats));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Talents));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Items));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Reputation));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Titles));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Professions));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Appearance));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Companions));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Mounts));
            EnqueueCallback(() => Assert.IsNull(briandek.Pets));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Achievements));
            EnqueueCallback(() => Assert.IsNotNull(briandek.Progression));

            EnqueueCallback(() => Assert.IsTrue(briandek.Name.Equals("briandek", StringComparison.InvariantCultureIgnoreCase)));

            EnqueueCallback(() => Assert.AreEqual(85, briandek.Level));
            EnqueueCallback(() => Assert.AreEqual(CharacterClass.WARRIOR, briandek.@Class));
            EnqueueCallback(() => Assert.AreEqual(CharacterRace.HUMAN, briandek.Race));
            EnqueueCallback(() => Assert.AreEqual(CharacterGender.MALE, briandek.Gender));

            EnqueueCallback(() => Assert.IsTrue(briandek.Talents.Where(t => t.Selected).FirstOrDefault().Name.Equals("protection", StringComparison.InvariantCultureIgnoreCase)));
            EnqueueCallback(() => Assert.IsTrue(briandek.Talents.ElementAt(1).Glyphs.Prime.ElementAt(0).Name.Equals("Glyph of Revenge", StringComparison.InvariantCultureIgnoreCase)));

            EnqueueCallback(() => Assert.IsTrue(briandek.Appearance.HairVariation == 13));
            EnqueueCallback(() => Assert.IsTrue(briandek.Companions.ElementAt(1) == 32298));
            EnqueueCallback(() => Assert.IsTrue(briandek.Items.AverageItemLevelEquipped == 364));

            EnqueueCallback(() => Assert.IsTrue(briandek.Mounts.Count() == 11));
            EnqueueTestComplete();

        }


        [TestMethod]
        [Asynchronous]
        public void Get_Complex_Character_Talasi_From_Skullcrusher()
        {
            bool done = false;
            var WowExplorer = new WowExplorer(Region.US);

            Character talasi = null;
            WowExplorer.GetCharacter("skullcrusher", "talasi", CharacterOptions.GetEverything, cb =>
            {
                talasi = cb.Result;
                done = true;
            });


            EnqueueConditional(() => done);
            EnqueueCallback(() => Assert.IsNotNull(talasi.Guild));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Stats));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Talents));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Items));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Reputation));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Titles));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Professions));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Appearance));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Companions));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Mounts));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Pets));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Achievements));
            EnqueueCallback(() => Assert.IsNotNull(talasi.Progression));

            EnqueueCallback(() => Assert.IsTrue(talasi.Pets.Any()));
            EnqueueCallback(() => Assert.IsTrue(talasi.Name.Equals("talasi", StringComparison.InvariantCultureIgnoreCase)));

            EnqueueCallback(() => Assert.AreEqual(85, talasi.Level));
            EnqueueCallback(() => Assert.AreEqual(CharacterClass.HUNTER, talasi.@Class));
            EnqueueCallback(() => Assert.AreEqual(CharacterRace.NIGHT_ELF, talasi.Race));
            EnqueueCallback(() => Assert.AreEqual(CharacterGender.MALE, talasi.Gender));

            EnqueueCallback(() => Assert.AreEqual(11, talasi.Mounts.Count()));
            EnqueueTestComplete();
        }
    }
}